package org.jimm.app;

import org.jimm.protocol.StatusInfo;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author r.u.s.h.a.n.
 */
public class StatusAdapter extends BaseAdapter {

    public static final int ADAPTER_STATUS = 0;
    public static final int ADAPTER_GLOBALSTATUS = 1;
    public static final int ADAPTER_PRIVATESTATUS = 2;

    Activity activity;
    int type;
    Object[] data = null;

    public StatusAdapter(Activity activity, int type) {
        this.activity = activity;
        this.type = type;
    }

    @Override
    public int getCount() {
        if (type == ADAPTER_STATUS || type == ADAPTER_GLOBALSTATUS) {
            return StatusInfo.statusNames.length;
        } else {
            return StatusInfo.privateStatusNames.length;
        }
    }

    @Override
    public Integer getItem(int position) {
        if (type == ADAPTER_STATUS) {
            return StatusInfo.statusIcons[position];
        } else if (type == ADAPTER_GLOBALSTATUS) {
            return StatusInfo.getGlobalStatusIcon(position);
        } else {
            return StatusInfo.privateStatusIcons[position];
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = LayoutInflater.from(activity).inflate(R.layout.status_item, null);

        ImageView statusImage = (ImageView) convertView.findViewById(R.id.status_image);
        TextView statusName = (TextView) convertView.findViewById(R.id.status_name);

        statusImage.setImageResource(getItem(position));

        if (type == ADAPTER_STATUS || type == ADAPTER_GLOBALSTATUS) {
            statusName.setText(StatusInfo.statusNames[position]);
        } else {
            statusName.setText(StatusInfo.privateStatusNames[position]);
        }
        return convertView;
    }
}